package stud.mpgame.net.command;

import org.apache.mina.core.session.IoSession;

import stud.mpgame.server.game.GameWorld;
import stud.mpgame.server.game.Player;

import stud.mpgame.snapshot.ICommand;
import stud.mpgame.snapshot.ISnapshot;

import java.util.Random;

/**
 * @author f.pavel91@gmail.com
 * @version 1.0
 */
public class AddPlayerCommand implements ICommand {

    private int time;
    private float x;
    private float y;
    private IoSession session;
    private int userID; //TODO

    public AddPlayerCommand(int time, IoSession session, int userID) {
        this.time = time;
        this.session = session;
        this.userID = userID;

        Random random = new Random();
        this.x = 600;//random.nextFloat() * 800;
        this.y = 50;//random.nextFloat() * 600;
    }

    public IoSession getSession() {
        return session;
    }

    public int getTime() {
        return time;
    }

    public int getUserID() {
        return userID;
    }

    public void apply(ISnapshot snapshot) {
        System.out.println("APPLIED...");
        ((GameWorld) snapshot).addPlayer(new Player(x, y, session, userID));
    }

    public String toString() {
        String result = "\n";
        result += "PlayerAddCommand:\n";
        result += "Time = " + time + "\n";
        result += "ID = " + userID + "\n";
        result += "X = " + x + "\n";
        result += "Y = " + y + "\n";
        return result;
    }

}
